import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
//callable的使用  创建线程的方式
public class Main {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Callable<Integer> callable = new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                int count = 0;
                for (int i = 0; i < 5000; i++) {
                    count++;
                }
                return count;
            }
        };
        //获取Callable的返回值  且把任务添加到线程里面
        FutureTask<Integer> futureTask = new FutureTask<Integer>(callable);
        Thread t = new Thread(futureTask);
        t.start();

        //t线程没有执行完时,会陷入阻塞,直到执行完才会获取Callable的返回值
        System.out.println(futureTask.get());
    }
}
